//
//  YSCommonReqTool.m
//  Yueshi
//
//  Created by Northwan on 16/4/5.
//  Copyright © 2016年 悦食中国. All rights reserved.
//

#import "YSCommonReqTool.h"
#import "YSHomeDataTool.h"

@implementation YSCommonReqTool

+(instancetype)sharedTool{
    static YSCommonReqTool *instance = nil;
    static dispatch_once_t predicate;
    dispatch_once(&predicate, ^{
        instance = [[self alloc] init];
    });
    return instance;
}

-(void)loadIndex:(YSBadgeType)badgeType callback:(void (^)(NSInteger count))callback{
    [YSHomeDataTool getSubscriptWithType:badgeType success:^(YSSubscriptModel *result){
        if(result.isSucc){
            callback(result.count);
            if(result.chatCount){
                [DefaultsHelper setBool:YES forKey:kHasNewChatMessage];
                [[NSNotificationCenter defaultCenter] postNotificationName:kDealNewMessageBadgeNortif object:nil];
            }
            [DefaultsHelper setInteger:result.count forKey:kCartIndex];
        }else{
            ShowEnterTips(result.data);
        }
    } failure:^(NSError *error) {
        ShowTips(kRequestFailure)
    }];
}

@end
